﻿using System;
using System.Collections.Generic;
using FoodRaidersWebAPI.domainnew.Article;
using FoodRaidersWebAPI.domainnew.Comment;
using FoodRaidersWebAPI.domainnew.Favorite;
using FoodRaidersWebAPI.domainnew.other;
using FoodRaidersWebAPI.Models;
using Microsoft.AspNetCore.Mvc;
/**
 * 初始化数据库
 */
namespace FoodRaidersWebAPI.Controllers
{
    [ApiController]
    [Route("[controller]/api")]
    public class InitController : Controller
    {
        private readonly FoodContext context;

        public InitController(FoodContext context)
        {
            this.context = context;
        }

        [HttpGet]
        public ActionResult<User> init()
        {
            //用户
            var u = new User()
            {
                UserID = 1, AvatarUrl = "用户1头像地址", Name = "用户1",
                FoodArticles = new List<FoodArticle>(),MerchantArticles = new  List<MerchantArticle>(),RaiderArticles = new List<RaiderArticle>(),
                FavoriteFoodArticles = new List<FavoriteFoodArticle>(),FavoriteMerchantArticles = new List<FavoriteMerchantArticle>(),FavoriteRaiderArticles = new List<FavoriteRaiderArticle>()
            };
            //文章属性
            List<Article> articles = new List<Article>();
            for (int i = 1; i <= 3; i++)
            {
                var a = new Article()
                {
                    ArticleID = i, PraiseNumber = 1, FavoriteNumber = 1, DateTime = DateTime.Now,
                    ArticleComments = new  List<ArticleComment>()
                    {
                        new ArticleComment()
                        {
                            ArticleCommentID = i,Content = "aaa",DateTime = DateTime.Now,PraiseNumber = 1,User = u
                        }
                    },
                    Pictures = new List<Picture>()
                    {
                        new Picture() {PictureID = i*2+0, FilePath = "图片地址"+i*2+0},
                        new Picture() {PictureID = i*2+1, FilePath = "图片地址2"+i*2+1}
                    }
                };
                articles.Add(a);
            }
            //美食
            var f = new Food()
            {
                FoodID = 1, Name = "热干面", Index = 5, Reason = "甜中带糯中带甜", Price = 3.5, AddressX = 1.1111,
                AddressY = 2.22222,
                LabelObjects = new List<LabelObject>()
                {
                    new LabelObject() {Label = Label.A, LabelObjectID = 1},
                    new LabelObject() {LabelObjectID = 2, Label = Label.C}
                }
            };
            //商家
            var m = new Merchant()
            {
                MerchantID = 1, Name = "梅园CBD", Index = 5, Reason = "经济实惠", Price = 66.6, AddressX = 1.234,
                AddressY = 4.321,
                Telephone = "123456789",
                Dashes = new List<Dash>()
                {
                    new Dash() {DashID = 1, Description = "这是第一个菜品", Name = "菜品一", Url = "菜品图片地址"},
                    new Dash() {DashID = 2, Description = "这是第二个菜品", Name = "菜品二", Url = "菜品图片地址"}
                }
            };
            //攻略
            var r = new Raider()
            {
                RaiderID = 1, Content = "攻略内容", Reason = "推荐理由", Title = "攻略标题",
            };
            //美食分享
            var fa = new FoodArticle()
            {
                FoodArticleID = 1, Article = articles[0], Food = f
            };
            u.FoodArticles.Add(fa);
            //商家分享
            var ma = new MerchantArticle()
            {
                MerchantArticleID = 1, Article = articles[1], Merchant = m
            };
            u.MerchantArticles.Add(ma);
            //攻略分享
            var ra = new RaiderArticle()
            {
                RaiderArticleID = 1, Article = articles[2], Raider = r
            };
            u.RaiderArticles.Add(ra);
            //收藏美食分享
            var ffa = new FavoriteFoodArticle()
            {
                FavoriteFoodArticleID = 1, DateTime = DateTime.Now, FoodArticle = fa
            };
            u.FavoriteFoodArticles.Add(ffa);
            //收藏商家分享
            var fma = new FavoriteMerchantArticle()
            {
                FavoriteMerchantArticleID = 1, DateTime = DateTime.Now, MerchantArticle = ma
            };
            u.FavoriteMerchantArticles.Add(fma);
            //收藏攻略分享
            var fra = new FavoriteRaiderArticle()
            {
                FavoriteRaiderArticleID = 1, DateTime = DateTime.Now, RaiderArticle = ra
            };
            u.FavoriteRaiderArticles.Add(fra);
            context.Users.Add(u);
            context.SaveChanges();
            return u;
        }
    }
}